<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta http-equiv="Content-Language" content="UTF-8" />
        <meta content="all" name="robots" />
        <meta name="author" content="Minit - CầnThơ IT" />
        <title>Demo Loại bỏ dấu tiếng việt trong chuỗi bằng JavaScript - CầnThơ IT</title>
        <script>
            function toNoneUTF8(searchKey) {
                var str = searchKey;
                str = str.toLowerCase();
                str= str.replace(/à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ/g,"a");
                str= str.replace(/è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ/g,"e");
                str= str.replace(/ì|í|ị|ỉ|ĩ/g,"i");
                str= str.replace(/ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ/g,"o");
                str= str.replace(/ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ/g,"u");
                str= str.replace(/ỳ|ý|ỵ|ỷ|ỹ/g,"y");
                str= str.replace(/đ/g,"d");
                return str;
            }

            function loadXMLDoc()
            {
                var xmlDOM;
                var searchString = "sau";
                var j = "";
                var xmlhttp = new XMLHttpRequest();
                xmlhttp.open("GET","Controller?btAction=loadXML",false);
                xmlhttp.send();
                if(xmlhttp.readyState == 4){
                    if(xmlhttp.status = 400){
                        xmlDOM = xmlhttp.responseXML;
                        var xpath = "//post/title";
                        var nodes = xmlDOM.evaluate(xpath, xmlDOM, null, XPathResult.ANY_TYPE, null);
                        var result=nodes.iterateNext();
                        while (result)
                        {
                            var str = toNoneUTF8(result.childNodes[0].nodeValue);
                            if(str.contains(searchString)) {
                                j += result.childNodes[0].nodeValue;
                            };
                            result=nodes.iterateNext();
                        }
                        document.getElementById("myDiv").innerHTML = j;
                    }
                
                } else {
                    alert("Can not connect");
                }
            }
        </script>
    </head>

    <body>

        <h2>My CD Collection:</h2>
        <div id="myDiv"></div>
        <input type="text" id="searchKey" value=""/>        
        <button type="button" onclick="loadXMLDoc()">Get my CD collection</button>
    </body>
</html>
